$(document).ready(function(){
	$("form").submit(function(){
		$(".validate_error").remove();
		var flag = true;
		$(this).find(".validate").each(function(i, t){
			//validate="empty,len(2|3),mail,telphone"
			var validates = $(t).attr("validate");
			if (validates != undefined && validates != "") {
				var vs = validates.split(",");
				for (var i = 0; i < vs.length; i++) {
					//验证是否为空
					if (vs[i] == "empty") {
						if ($(t).val() == "") {
//							var txt = $(t).attr("validate-text");
//							if (txt == undefined || txt == "") {
//								txt = message_validate_empty;
//							}
							$(t).after("<span class='validate_error'>" + message_validate_empty + "<a class='close' style='float:none;margin-left:8px;' data-dismiss='alert'>×</a></span>");
							flag = false;
							break;
						}
					} else if (vs[i].length > 3 && vs[i].substring(0,3) == "len") {
						var nums = vs[i].substring(vs[i].indexOf("(") + 1, vs[i].indexOf(")")).split("|");
						if (nums.length == 1) {
							nums[1] = 255;
						}
						if (nums.length == 2) {
							var min = nums[0];
							var max = nums[1];
							min = isNaN(min) ? 0 : parseInt(min);
							max = isNaN(max) ? 255 : parseInt(max);
							if ($(t).val().length < min || $(t).val().length > max) {
								$(t).after("<span class='validate_error'>" + message_validate_len.format(min, max) + "<a class='close' style='float:none;margin-left:8px;' data-dismiss='alert'>×</a></span>");
								flag = false;
								break;
							}
						}
					}
				}
			}
		});
		return flag;
	});
});